package com.snline.crm.logistics.action;

import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * action鍩虹被, 缁ф壙鑷狝ctionSupport绫�  
 * 涓哄瓙绫绘彁渚泂truts2 map绫诲瀷session瀵硅薄
 * 鎻愪緵鍒嗛〉宸ュ叿鍙橀噺绛�
 */
public class BaseAction extends ActionSupport implements SessionAware,ServletRequestAware {
	private static final long serialVersionUID = 1L;
	
	protected int page = 1;
	protected String pageTool;
	protected Map<String, Object> session;
	protected HttpServletRequest servletRequest;

	
	@Override//閲嶅啓鑷埗鎺ュ彛SessionAware鐨勬柟娉�,鏈夊鍣ㄨ嚜琛岃皟鐢ㄥ苟缁檚ession瀵硅薄璧嬪��
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	//鐢ㄤ簬鍦ㄥ瓙绫讳腑鑾峰彇session瀵硅薄
	public Map<String, Object> getSession(){
		return session;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getPageTool() {
		return pageTool;
	}

	public void setPageTool(String pageTool) {
		this.pageTool = pageTool;
	}

	@Override
	public void setServletRequest(HttpServletRequest servletRequest) {
		this.servletRequest = servletRequest;
	}
	
	/**
	 * 杩斿洖鍝嶅簲鏁版嵁
	 * @param msg
	 */
	protected void sendResponseMsg(String msg) {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html");
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-store");
		response.addHeader("Cache-Control", "must-revalidate");
		response.addHeader("Cache-Control", "post-check=0, pre-check=0");
		response.setDateHeader("Expires", 0);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.print(msg);
		} catch (Throwable e) {
			e.printStackTrace();
		} finally {
			out.close();
		}
	}

}
